    LIST r=dec
	#include <p18f4431.inc>
    #include "padnest-pic18f-langext-v1.4.inc"
    #include "padnest-mpasm-structs-v1.0.inc"


; configs
	CONFIG OSC = HS
	CONFIG IESO = OFF
	CONFIG FCMEN = OFF
	CONFIG PWRTEN = ON
	CONFIG WDTEN = OFF
	CONFIG BOREN = OFF
	CONFIG MCLRE = ON
	CONFIG LVP = OFF
	CONFIG DEBUG = OFF
	CONFIG STVREN = ON

; registers
	UDATA
REGX		res 1
REGY		res 1
REGZ		res 1
REGU		res 1
REGH		res 1
REGL    	res 1

; reset vector
	ORG	0x0000
	goto	main

; interrupt vector in compatibility mode
	ORG	0x0008

main:
	goto test_1_1


; DO-FOREVER: exiting from innermost loop when REGX = 0x03 by exitdo command
test_1_1:
	movlf 0x01, REGX
	do
		do
			ifl	REGX, EQ, 0x03
				exitdo
			endi
			incf REGX
		forever
		incf REGX
	untilfl REGX, EQ, 0x04
	nop

; DO-UNTIL: exiting from loop when REGX = 0x03
test_1_2:
	movlf 0x01, REGX
	do
		incf REGX
	untilfl REGX, EQ, 0x03
	nop

; DO-UNTIL: exiting from loop when REGX > REGY (REGX = 4)
test_1_3:
	movlf 0x01, REGX
	movlf 0x03, REGY
	do
		incf REGX
	untilff REGX, GT, REGY
	nop

; DO-UNTIL: exiting from loop if bit REGX.2 is set
test_1_4:
	movlf 0x01, REGX
	do
		incf REGX
	untilfset REGX, 2, BANKED
	nop

; DO-UNTIL: exiting from loop if bit REGX.1 is clear
test_1_5:
	movlf 0x03, REGX
	do
		decf REGX
	untilfclr REGX, 1, BANKED
	nop


; FOR-NEXT: nested for loops (REGZ = 9 at the end)
test_2_1:
	movlf 0x00, REGZ
	for REGX, 1, 3
		for REGY, 1, 3
			incf REGZ
		next REGY
	next REGX
	nop

; FOR-NEXT: nested for loops with inner step 2 (REGZ = 6 at the end)
test_2_2:
	movlf 0x00, REGZ
	for REGX, 1, 3
		for REGY, 1, 3
			incf REGZ
		nextl REGY, 2
	next REGX
	nop


; SWITCH-CASE: exits from do loop when REGX = 0x07 (default case)
test_4_1:
	movlf 0x01, REGX
	do
		switchf REGX
			casel 0x01
				nop			; executed 1 time
			break;
			casel 0x02
			casel 0x03
				nop			; executed 2 times
			break
			casel 0x04
			casel 0x05
			casel 0x06
				nop			; executed 3 times
			break
			default
				exitdo
		endswitch
		incf REGX
	forever
	nop


; WHILE: exits from loop when REGX = 0x04
test_5_1:
	movlf 0x01, REGX
	whilefl	REGX, LT, 0x04
		incf REGX
	endwhile

; WHILE: exits from loop when REGX < REGY (REGX = 0x06)
test_5_2:
	movlf 0x0A, REGX
	movlf 0x07, REGY
	whileff	REGX, GE, REGY
		decf REGX
	endwhile
	nop

	do
	forever

	END


